home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Science / µSim 1.0 folder / source / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-08  |  17.4 KB  |  704 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12. #include    "UtilsSys7.h"
  13. #include    "AEHandlers.h"
  14. #include    "CursorBalloon.h"
  15. #include    "ControlStore.h"
  16. #include    "Disasm.h"
  17. #include    "Dump.h"
  18. #include    "DoMenu.h"
  19. #include    "FabTaskManager.h"
  20. #include    "Globals.h"
  21. #include    "InitMenus.h"
  22. #include    "Input.h"
  23. #include    "Main.h"
  24. #include    "Microprogram_Ed.h"
  25. #include    "Preferences.h"
  26. #include    "Simulator.h"
  27. #include    "SimUtils.h"
  28.  
  29. #if defined(FabSystem7orlater)
  30.  
  31. #pragma segment Main
  32.  
  33. extern void _DATAINIT(void);
  34.  
  35. static void DoDiskEvent(void);
  36. static void MyZoom(WindowPtr whichWindow, short code);
  37. static Boolean CheckTheStack(void);
  38. static void AvoidMenuSelections(void);
  39. static void WantMenuSelections(void);
  40. static void AEErrorAlert(OSErr reason);
  41.  
  42. void main(void);
  43.  
  44.  
  45. /* DomyKeyEvent: we got a key down, of course */
  46.  
  47. void DomyKeyEvent(EventRecord *evt)
  48. {
  49. enum {
  50. kUndoKey = 0x7A10,
  51. kCutKey = 0x7810,
  52. kCopyKey = 0x6310,
  53. kPasteKey = 0x7610,
  54. kHelpKey = 0x7205,
  55. kFwdDel = 0x757F,
  56. kHomeKey = 0x7301,
  57. kEndKey = 0x7704,
  58. kPgUpKey = 0x740B,
  59. kPgDnKey = 0x790C,
  60. kClearKey = 0x471B,
  61. kEnterKey = 0x4C03
  62. };
  63.  
  64. register WindowPtr    frontW;
  65. register short    txtStart;
  66. register unsigned char    ch;
  67.  
  68. frontW = FrontWindow();
  69. ch = CHARFROMMESSAGE(evt->message);
  70. if (evt->modifiers & cmdKey) {
  71.     AdjustMenus();
  72.     Handle_My_Menu(MenuKey(ch));
  73.     }
  74. else {
  75.     switch ((unsigned short)evt->message) {
  76.         case kUndoKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Undo);
  77.             break;
  78.         case kCutKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Cut);
  79.             if (gWPtr_Microprogram_Ed == frontW)
  80.                 Key_Microprogram_Ed(evt, true);
  81.             break;
  82.         case kCopyKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Copy);
  83.             break;
  84.         case kPasteKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Paste);
  85.             if (gWPtr_Microprogram_Ed == frontW)
  86.                 Key_Microprogram_Ed(evt, true);
  87.             break;
  88.         case kHelpKey    :    (void)HMSetBalloons(1 - HMGetBalloons());
  89.                             RecalcMouseRegion(frontW, evt->where);
  90.             break;
  91.         case kFwdDel    :
  92.             if (gTheInput) {
  93.                 if ((txtStart = (*gTheInput)->selStart) == (*gTheInput)->selEnd)
  94.                     TESetSelect(txtStart, txtStart + 1, gTheInput);
  95.                 TEDelete(gTheInput);
  96.                 if (gWPtr_Microprogram_Ed == frontW)
  97.                     Key_Microprogram_Ed(evt, true);
  98.                 }
  99.             break;
  100.         case kClearKey    :
  101.             if (gTheInput) {
  102.                 TEDelete(gTheInput);
  103.                 if (gWPtr_Microprogram_Ed == frontW)
  104.                     Key_Microprogram_Ed(evt, true);
  105.                 }
  106.             break;
  107.         case kHomeKey    :
  108.             if (gWPtr_Dump == frontW)
  109.                 DumpHome();
  110.             else if (gWPtr_Disasm == frontW)
  111.                 DisasmHome();
  112.             else if (gWPtr_IO == frontW)
  113.                 IOHome();
  114.             break;
  115.         case kEndKey    :
  116.             if (gWPtr_Dump == frontW)
  117.                 DumpEnd();
  118.             else if (gWPtr_Disasm == frontW)
  119.                 DisasmEnd();
  120.             else if (gWPtr_IO == frontW)
  121.                 IOEnd();
  122.             break;
  123.         case kPgUpKey    :
  124.             if (gWPtr_Dump == frontW)
  125.                 DumpPgUp();
  126.             else if (gWPtr_Disasm == frontW)
  127.                 DisasmPgUp();
  128.             else if (gWPtr_IO == frontW)
  129.                 IOPgUp();
  130.             break;
  131.         case kPgDnKey    :
  132.             if (gWPtr_Dump == frontW)
  133.                 DumpPgDn();
  134.             else if (gWPtr_Disasm == frontW)
  135.                 DisasmPgDn();
  136.             else if (gWPtr_IO == frontW)
  137.                 IOPgDn();
  138.             break;
  139.         case kEnterKey:
  140.             if (gTheInput) {
  141.                 TESelView(gTheInput);
  142.                 if (gWPtr_IO == frontW)
  143.                     AdjustScrollbars(frontW, false);
  144.                 }
  145.             break;
  146.         default:
  147.             if (gWPtr_Microprogram_Ed == frontW)
  148.                 Key_Microprogram_Ed(evt, false);
  149.             else
  150.                 DoKeyDown(frontW, ch, true);
  151.         }
  152.     }
  153. }
  154.  
  155. /* DoDiskEvent: checks for inserted disks */
  156.  
  157. void DoDiskEvent(void)
  158. {
  159. if (HiWrd(gMyEvent.message)) {
  160. //    myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left)>>1) - (304 / 2);
  161. //    myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);
  162.     InitCursor();
  163.     DILoad();
  164.     (void)DIBadMount(gMyEvent.where, gMyEvent.message);
  165.     DIUnload();
  166.     }
  167. }
  168.  
  169. /* DoZoom: a window was zoomed */
  170.  
  171. void MyZoom(WindowPtr whichWindow, short code)
  172. {
  173. Rect    globalPortRect, theSect, zoomRect;
  174. GDHandle    nthDevice, dominantGDevice;
  175. register RectPtr    rectP;
  176. long    sectArea, greatestArea;
  177. short    bias;
  178.  
  179. /* theEvent is a global EventRecord from the main event loop */
  180. /* savePort is a global GrafPtr for scratch */
  181.  
  182. EraseRect(&whichWindow->portRect);
  183.  
  184. /* If there is the possibility of multiple gDevices, then we */
  185. /* must check them to make sure we are zooming onto the right */
  186. /* display device when zooming out. */
  187. if ((code == inZoomOut) && gHasColorQD) {
  188.     /* window's portRect must be converted to global coordinates */
  189.     globalPortRect = whichWindow->portRect;
  190.     LocalToGlobal(&topLeft(globalPortRect));
  191.     LocalToGlobal(&botRight(globalPortRect));
  192.     /* must calculate height of window's title bar */
  193.     bias = globalPortRect.top - 1 - (*((WindowPeek)whichWindow)->strucRgn)->rgnBBox.top;
  194.     nthDevice = GetDeviceList();
  195.     greatestArea = 0;
  196.     /* This loop checks the window against all the gdRects in the */
  197.     /* gDevice list and remembers which gdRect contains the largest */
  198.     /* portion of the window being zoomed. */
  199.     while (nthDevice) {
  200.         (void)SectRect(&globalPortRect, &(*nthDevice)->gdRect, &theSect);
  201.         sectArea = (long)(theSect.right - theSect.left) * (theSect.bottom - theSect.top);
  202.         if (sectArea > greatestArea) {
  203.             greatestArea = sectArea;
  204.             dominantGDevice = nthDevice;
  205.             }
  206.         nthDevice = GetNextDevice(nthDevice);
  207.         }
  208.     /* We must create a zoom rectangle manually in this case. */
  209.     /* account for menu bar height as well, if on main device */
  210.     if (dominantGDevice == GetMainDevice())
  211.         bias += GetMBarHeight();
  212.     rectP = &(*dominantGDevice)->gdRect;
  213.     zoomRect.top = rectP->top + bias + 3;
  214.     zoomRect.left = rectP->left + 3;
  215.     zoomRect.bottom = rectP->bottom - 3;
  216.     zoomRect.right = rectP->right - 3;
  217.     /* Set up the WStateData record for this window. */
  218.     (*(WStateDataHandle)((WindowPeek)whichWindow)->dataHandle)->stdState = zoomRect;
  219.     }
  220. ZoomWindow(whichWindow, code, true);
  221.  
  222. }
  223.  
  224. /* DoCloseWindow: a window must be closed */
  225.  
  226. void DoCloseWindow(WindowPtr w, short whichMenuItem)
  227. {
  228. HideWindow(w);
  229. CheckItem(gMenu_Windows, whichMenuItem, false);
  230. }
  231.  
  232.  
  233. void DoUpdate(EventRecord *passEvt)
  234. {
  235. GrafPtr        savePort;
  236. register WindowPtr    w;
  237. register void (*theProc)(WindowPtr);
  238.  
  239. GetPort(&savePort);
  240. SetPort(w = (WindowPtr)passEvt->message);
  241. BeginUpdate(w);
  242. if (IsFabWindow(w)) {
  243.     theProc = ((FabWindowPtr)w)->updateProc;
  244.     if (theProc)
  245.         theProc(w);
  246.     }
  247. EndUpdate(w);
  248. SetPort(savePort);
  249. }
  250.  
  251. void DoActivate(EventRecord *passEvt)
  252. {
  253. register WindowPtr    whichWindow;
  254.  
  255. whichWindow = (WindowPtr)passEvt->message;
  256. DecideActivation(passEvt, whichWindow, passEvt->where, passEvt->modifiers & activeFlag);
  257. }
  258.  
  259. /* DecideActivation: common routine because of activate and
  260. suspend&resume events */
  261.  
  262. void DecideActivation(EventRecord *evt, WindowPtr w, Point mouseGlob, Boolean active)
  263. {
  264. GrafPtr    savePort;
  265. register void (*theActivProc)(EventRecord *, WindowPtr, Boolean);
  266.  
  267. GetPort(&savePort);
  268. SetPort(w);
  269.  
  270. if (IsFabWindow(w)) {
  271.     theActivProc = ((FabWindowPtr)w)->activateProc;
  272.     if (theActivProc)
  273.         theActivProc(evt, w, active);
  274.     }
  275. if (active) {
  276.     RecalcMouseRegion(w, mouseGlob);
  277.     }
  278. SetPort(savePort);
  279. }
  280.  
  281. void DoOSEvent(EventRecord *passEvt)
  282. {
  283. register WindowPtr    frontW = FrontWindow();
  284. register Boolean    willbeActive;
  285.  
  286. if ((*(Byte *)&passEvt->message) == suspendResumeMessage) {
  287.     InitCursor();
  288.     if (willbeActive = (CHARFROMMESSAGE(passEvt->message) & resumeFlag)) {
  289.         /* resume */
  290.         gInTheForeground = true;
  291.         if (CHARFROMMESSAGE(passEvt->message) & convertClipboardFlag)
  292.             (void)TEFromScrap();
  293.         }
  294.     else {
  295.         /* suspend */
  296.         gInTheForeground = false;
  297.         }
  298.     if (frontW)
  299.         DecideActivation(passEvt, frontW, passEvt->where, willbeActive);
  300.     }
  301.  
  302. else if ((*(Byte *)&passEvt->message) == mouseMovedMessage) {
  303.         RecalcMouseRegion(frontW, passEvt->where);
  304.         }
  305. }
  306.  
  307. void DoHighLevelEvent(EventRecord *evt)
  308. {
  309. OSErr    err;
  310.  
  311. err = AEProcessAppleEvent(evt);
  312. if (err)
  313.     if (err != userCanceledErr && err != errAEEventNotHandled) {
  314.         AEErrorAlert(err);
  315.         UnloadSeg(AEErrorAlert);
  316.         }
  317. }
  318.  
  319. void main(void)
  320. {
  321. GrafPtr        savePort;
  322. WindowPtr    w;
  323. register void (*theProc)(WindowPtr);
  324. register void (*theDoGrowProc)(WindowPtr, EventRecord *);
  325. register RectPtr    wStateP;
  326. register short    code;
  327.  
  328. MaxApplZone();
  329. //UnloadSeg(_DATAINIT);
  330. InitAll();
  331. UnloadSeg(InitAll);
  332. do {
  333. if (gRstatus)
  334.     gSleep = 0L;
  335. else if (gInTheForeground && gTheInput && ((*gTheInput)->selStart == (*gTheInput)->selEnd))
  336.     gSleep = LMGetCaretTime();
  337. else
  338.     gSleep = ULONG_MAX;
  339.  
  340.     if (WaitNextEvent(everyEvent, &gMyEvent, gSleep, mouseRgn)) {
  341.         switch (gMyEvent.what) {
  342.             case nullEvent :
  343.                 DoIdle();
  344.             case mouseDown :
  345.                 code = FindWindow(gMyEvent.where, &w);
  346.                 switch (code) {
  347.                     case inMenuBar :
  348.                         AdjustMenus();
  349.                         Handle_My_Menu(MenuSelect(gMyEvent.where));
  350.                         break;
  351.                     case inDrag :
  352.                         DragWindow(w, gMyEvent.where, &qd.screenBits.bounds);
  353.                         GetPort(&savePort);
  354.                         SetPort(w);
  355.                         if (((WindowPeek)w)->spareFlag) {
  356.                             wStateP = &(*(WStateDataHandle)((WindowPeek)w)->dataHandle)->userState;
  357.                             *wStateP = w->portRect;
  358.                             LocalToGlobal(&topLeft(*wStateP));
  359.                             LocalToGlobal(&botRight(*wStateP));
  360.                             }
  361.                         if (IsFabWindow(w)) {
  362.                             theProc = ((FabWindowPtr)w)->dragProc;
  363.                             if (theProc)
  364.                                 theProc(w);
  365.                             RecalcGlobalCoords((FabWindowPtr)w);
  366.                             }
  367.                         (void) EventAvail(0, &gMyEvent);
  368.                         RecalcMouseRegion(w, gMyEvent.where);
  369.                         SetPort(savePort);
  370.                         break;
  371.                     case inGrow :
  372.                         GetPort(&savePort);
  373.                         SetPort(w);
  374.                         if (IsFabWindow(w)) {
  375.                             theDoGrowProc = ((FabWindowPtr)w)->growProc;
  376.                             if (theDoGrowProc)
  377.                                 theDoGrowProc(w, &gMyEvent);
  378.                             ResizeObjects((FabWindowPtr)w);
  379.                             RecalcGlobalCoords((FabWindowPtr)w);
  380.                             }
  381.                         (void) EventAvail(0, &gMyEvent);
  382.                         RecalcMouseRegion(w, gMyEvent.where);
  383.                         SetPort(savePort);
  384.                         break;
  385.                     case inZoomIn :
  386.                     case inZoomOut :
  387.                         GetPort(&savePort);
  388.                         SetPort(w);
  389.                         if (TrackBox(w, gMyEvent.where, code)) {
  390.                             MyZoom(w, code);
  391.                             
  392.                             if (IsFabWindow(w)) {
  393.                                 theProc = ((FabWindowPtr)w)->zoomProc;
  394.                                 if (theProc)
  395.                                     theProc(w);
  396.                                 ResizeObjects((FabWindowPtr)w);
  397.                                 RecalcGlobalCoords((FabWindowPtr)w);
  398.                                 }
  399.                             }
  400.                         (void) EventAvail(0, &gMyEvent);
  401.                         RecalcMouseRegion(w, gMyEvent.where);
  402.                         SetPort(savePort);
  403.                         break;
  404.                     case inGoAway :
  405.                         if (TrackGoAway(w, gMyEvent.where)) {
  406.                             theProc = ((FabWindowPtr)w)->goAwayProc;
  407.                             if (theProc)
  408.                                 theProc(w);
  409.                             }
  410.                         break;
  411.                     case inContent :
  412.                         if (w != FrontWindow()) 
  413.                             SelectWindow(w);
  414.                         else {
  415.                             if (IsFabWindow(w)) {
  416.                                 GetPort(&savePort);
  417.                                 SetPort(w);
  418.                                 theDoGrowProc = ((FabWindowPtr)w)->contentProc;
  419.                                 if (theDoGrowProc)
  420.                                     theDoGrowProc(w, &gMyEvent);
  421.                                 SetPort(savePort);
  422.                                 }
  423.                             }
  424.                         break;
  425.                     case inSysWindow :
  426.                         SystemClick(&gMyEvent, w);
  427.                         break;
  428.                     }
  429.                 break;
  430.             case keyDown:
  431.             case autoKey:
  432.                 DomyKeyEvent(&gMyEvent);
  433.                 break;
  434.             case updateEvt :
  435.                 DoUpdate(&gMyEvent);
  436.                 break;
  437.             case diskEvt :
  438.                 DoDiskEvent();
  439.                 break;
  440.             case activateEvt :
  441.                 DoActivate(&gMyEvent);
  442.                 break;
  443.             case osEvt :
  444.                 DoOSEvent(&gMyEvent);
  445.                 break;
  446.             case kHighLevelEvent:
  447.                 DoHighLevelEvent(&gMyEvent);
  448.                 break;
  449.             }
  450.         }
  451.     else
  452.         DoIdle();
  453.     }
  454. while (gDoneFlag == false);
  455. SavePreferencesFile();
  456. CleanUp();
  457. }
  458.  
  459. /* DoIdle: so that we have something to do while the user has nothing to do */
  460.  
  461. void DoIdle(void)
  462. {
  463. enum {
  464. kMIN_COMPUTE = 5L
  465. };
  466.  
  467. long    tickc;
  468. Boolean    stackProblems;
  469.  
  470. CheckCallQueue();
  471. if (gInTheForeground)
  472.     if (gTheInput)
  473.         TEIdle(gTheInput);
  474.  
  475. if (gRstatus) {
  476.     if (CheckTheStack() == false) {
  477.         if (gPwrManagerIsPresent)
  478.             (void)IdleUpdate();
  479.         switch (gRstatus) {
  480.             case kST_GOING:
  481.                 tickc = TickCount();
  482.                 do {
  483.                     ExecuteInstructionsGO();
  484.                     stackProblems = CheckTheStack();
  485.                     }
  486.                 while ((TickCount() - tickc < kMIN_COMPUTE) && (stackProblems == false));
  487.                 break;
  488.             case kST_STEPASM:
  489.                 ExecuteInstructionsGO();
  490.                 StopIt();
  491.                 break;
  492.             case kST_STEPMPROG:
  493.                 ExecuteInstructions(gSubclk++);
  494.                 gSubclk &= 3;
  495.                 if (gSubclk == 0)
  496.                     gRstatus = kST_STOPPED;
  497.                 break;
  498.             case kST_STEPSUBCYC:
  499.                 ExecuteInstructions(gSubclk++);
  500.                 gSubclk &= 3;
  501.                 gRstatus = kST_STOPPED;
  502.                 break;
  503.             }
  504.         }
  505.     }
  506. }
  507.  
  508. Boolean CheckTheStack(void)
  509. {
  510. Boolean    result = true;
  511.  
  512. if ((unsigned short)gRegs[kREG_SP] > gPrefs.DefSPValue) {
  513.     if (gRegs[kREG_PC] == kPCExitToShell)
  514.         (void)NoteAlert_AE(kALRT_TOSHELL, myStdFilterProcNoCancel, myIdleFunct);
  515.     else
  516.         (void)StopAlert_AE(kALRT_STKUNDERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  517.     StopIt();
  518.     }
  519. else if ((unsigned short)gRegs[kREG_SP] < (gPrefs.DefSPValue - gPrefs.DefStkSize)) {
  520.     (void)StopAlert_AE(kALRT_STKOVERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  521.     StopIt();
  522.     }
  523. else
  524.     result = false;
  525. return result;
  526. }
  527.  
  528. /* AdjustMenus: we set the menus before MenuSelect or MenuKey.
  529. (Agh! This commonly used technique prevents tear-off menus) */
  530.  
  531. void AdjustMenus(void)
  532. {
  533. register WindowPtr    window;
  534. long    offset;
  535. Boolean    undo = false;
  536. Boolean    cutCopyClear = false;
  537. Boolean    paste = false;
  538. Boolean    insertdelete = false;
  539. Boolean    go = false;
  540. Boolean    step = false;
  541. Boolean    stop = false;
  542.  
  543. if (window = FrontWindow()) {
  544.     if ( ISDAWINDOW(window) || isMovableModal(window)) {
  545.         undo = true;                /* all editing is enabled for DA windows */
  546.         cutCopyClear = true;
  547.         paste = true;
  548.         }
  549.     else if ( ISAPPWINDOW(window) ) {
  550.     /* Cut, Copy, and Clear is enabled for appl. windows with selections */
  551.         if (gTheInput) {
  552.             EnableItem(gMenu_Edit, kMItem_Select_All);
  553.             if ( (*gTheInput)->selStart < (*gTheInput)->selEnd )
  554.                 cutCopyClear = true;
  555.             }
  556.         else
  557.             DisableItem(gMenu_Edit, kMItem_Select_All);
  558.         if ((window == gWPtr_Microprogram_Ed) && (keyDownDest == kKEY_LIST)) {
  559.             cutCopyClear = true;
  560.             if (theSelection[kL_COMMENTS] != maxLLine[kL_COMMENTS])
  561.                 insertdelete = true;
  562.             }
  563.     /* if there’s any text in the clipboard, paste is enabled */
  564.         if ((GetScrap(nil, 'TEXT', &offset)  > 0) &&
  565.             ((gTheInput) || ((window == gWPtr_Microprogram_Ed) && (keyDownDest == kKEY_LIST))))
  566.             paste = true;
  567.         }
  568.     if ( undo )
  569.         EnableItem(gMenu_Edit, kMItem_Undo);
  570.     else
  571.         DisableItem(gMenu_Edit, kMItem_Undo);
  572.     if ( cutCopyClear ) {
  573.         EnableItem(gMenu_Edit, kMItem_Cut);
  574.         EnableItem(gMenu_Edit, kMItem_Copy);
  575.         EnableItem(gMenu_Edit, kMItem_Clear);
  576.         }
  577.     else {
  578.         DisableItem(gMenu_Edit, kMItem_Cut);
  579.         DisableItem(gMenu_Edit, kMItem_Copy);
  580.         DisableItem(gMenu_Edit, kMItem_Clear);
  581.         }
  582.     if ( paste )
  583.         EnableItem(gMenu_Edit, kMItem_Paste);
  584.     else
  585.         DisableItem(gMenu_Edit, kMItem_Paste);
  586.     if ( insertdelete ) {
  587.         EnableItem(gMenu_Edit, kMItem_Insert);
  588.         EnableItem(gMenu_Edit, kMItem_Delete);
  589.         }
  590.     else {
  591.         DisableItem(gMenu_Edit, kMItem_Insert);
  592.         DisableItem(gMenu_Edit, kMItem_Delete);
  593.         }
  594.     if (isMovableModal(window))
  595.         AvoidMenuSelections();
  596.     else
  597.         WantMenuSelections();
  598.     }
  599. else {    /* no windows are open */
  600.     DisableItem(gMenu_Edit, kMItem_Undo);    /* check this when implementing undo */
  601.     DisableItem(gMenu_Edit, kMItem_Cut);
  602.     DisableItem(gMenu_Edit, kMItem_Copy);
  603.     DisableItem(gMenu_Edit, kMItem_Clear);
  604.     DisableItem(gMenu_Edit, kMItem_Paste);
  605.     DisableItem(gMenu_Edit, kMItem_Select_All);
  606.     DisableItem(gMenu_Edit, kMItem_Insert);
  607.     DisableItem(gMenu_Edit, kMItem_Delete);
  608.     }
  609.  
  610. if (((WindowPeek)gWPtr_Disasm)->visible)
  611.     EnableItem(gMenu_Control, kMItem_Disasmfrom);
  612. else
  613.     DisableItem(gMenu_Control, kMItem_Disasmfrom);
  614.  
  615. if (((WindowPeek)gWPtr_Dump)->visible)
  616.     EnableItem(gMenu_Control, kMItem_Dumpfrom);
  617. else
  618.     DisableItem(gMenu_Control, kMItem_Dumpfrom);
  619.  
  620. if (DocIsOpen) {
  621.     if (gRstatus == kST_STOPPED) {
  622.         go = true;
  623.         step = true;
  624.         }
  625.     if (gRstatus == kST_GOING) {
  626.         stop = true;
  627.         }
  628.     EnableItem(gMenu_Windows, kMItem_Microprogram);
  629.     EnableItem(gMenu_File, kMItem_Close);
  630.     EnableItem(gMenu_File, kMItem_Save_Control_St2);
  631.     EnableItem(gMenu_File, kMItem_Save_CS_Stationery);
  632.     EnableItem(gMenu_Control, kMItem_SelectCurMPC);
  633.     }
  634. else {
  635.     DisableItem(gMenu_Windows, kMItem_Microprogram);
  636.     DisableItem(gMenu_File, kMItem_Close);
  637.     DisableItem(gMenu_File, kMItem_Save_Control_St2);
  638.     DisableItem(gMenu_File, kMItem_Save_CS_Stationery);
  639.     DisableItem(gMenu_Control, kMItem_SelectCurMPC);
  640.     }
  641. if (go)
  642.     EnableItem(gMenu_Control, kMItem_Go);
  643. else
  644.     DisableItem(gMenu_Control, kMItem_Go);
  645. if (step) {
  646.     EnableItem(gMenu_Control, kMItem_StepSub);
  647.     EnableItem(gMenu_Control, kMItem_StepMicro);
  648.     EnableItem(gMenu_Control, kMItem_StepInstr);
  649.     }
  650. else {
  651.     DisableItem(gMenu_Control, kMItem_StepSub);
  652.     DisableItem(gMenu_Control, kMItem_StepMicro);
  653.     DisableItem(gMenu_Control, kMItem_StepInstr);
  654.     }
  655. if (stop)
  656.     EnableItem(gMenu_Control, kMItem_Stop);
  657. else
  658.     DisableItem(gMenu_Control, kMItem_Stop);
  659. if (gRstatus == kST_GOING) {
  660.     DisableItem(gMenu_Control, kMItem_ResetMem);
  661.     DisableItem(gMenu_Control, kMItem_ResetRegs);
  662.     }
  663. else {
  664.     EnableItem(gMenu_Control, kMItem_ResetMem);
  665.     EnableItem(gMenu_Control, kMItem_ResetRegs);
  666.     }
  667. } /*AdjustMenus*/
  668.  
  669. void AvoidMenuSelections(void)
  670. {
  671. DisableItem(gMenu_File, 0);
  672. DisableItem(gMenu_Apple, 1);
  673. DisableItem(gMenu_Windows, 0);
  674. DisableItem(gMenu_Control, 0);
  675. DisableItem(gMenu_Assembler, 0);
  676. }
  677.  
  678. void WantMenuSelections(void)
  679. {
  680. EnableItem(gMenu_File, 0);
  681. EnableItem(gMenu_Apple, 1);
  682. EnableItem(gMenu_Windows, 0);
  683. EnableItem(gMenu_Control, 0);
  684. EnableItem(gMenu_Assembler, 0);
  685. }
  686.  
  687. #pragma segment Rare
  688.  
  689. /* AEErrorAlert: errors while handling AEvents */
  690.  
  691. static void AEErrorAlert(OSErr reason)
  692. {
  693. Str255    tempS;
  694.  
  695. MyNumToString(reason, tempS);
  696. ParamText(tempS, nil, nil, nil);
  697. (void)StopAlert_UPP(kALRT_AEPROCESSERR, myStdFilterProcNoCancel);
  698. }
  699.  
  700. #pragma segment Main
  701.  
  702. #endif
  703.  
  704.